package com.example.managerment.module.vo;

import com.alibaba.fastjson.JSON;
import jdk.nashorn.internal.parser.JSONParser;
import lombok.Data;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 *
 * 封装统一响应数据格式
 */
@Data
public class ResultVO<T> {
    private Integer code;//响应代码
    private String msg;//响应信息
    private T data;//响应数据

    //增,删,改
    public ResultVO(){
        this.code = 1000;
        this.msg = "成功";
    }

    //查询
    public ResultVO(T data){
        this.code = 1000;
        this.msg = "成功";
        this.data = data;
    }

    public void out(HttpServletResponse response) throws IOException {
        response.setContentType("text/json;charset=utf-8");
        response.getWriter().write(JSON.toJSONString(this));
    }
}
